// ChildView.cpp : CChildView 类的实现
//

#include "stdafx.h"
#include "Paper.h"
#include "ChildView.h"

#include "Line.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CChildView

CChildView::CChildView()
{
	this->tick = 2;
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView, CWnd)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()



// CChildView 消息处理程序

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // 用于绘制的设备上下文
	
	// 获取客户区域矩形
	CRect rect;
	GetClientRect( &rect );

	PaperLine line(tick);

	line.FixPosition(rect.Width() - 100, rect.Height() - 100);

	dc.OffsetViewportOrg(50, 50);

	dc.MoveTo(line.data[0].x, line.data[0].y);

	for(int i = 1; i < line.Size; i++)
	{
		dc.LineTo(line.data[i].x, line.data[i].y);
	}
}
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
	tick = ( ++tick ) % 22;
	if(tick < 2) tick = 2;

	Invalidate();							// 窗体无效
	UpdateWindow();							// 重画窗体

	CWnd::OnLButtonDown(nFlags, point);
}
